package ui;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.util.Random;

public class LoginJFrame extends JFrame implements KeyListener, ActionListener {
    JButton jtb1=new JButton(new ImageIcon("D:\\IJ\\javaCode\\puzzleGame\\engineering-practice-\\image\\login\\登录按钮.png"));
    JButton jtb2=new JButton(new ImageIcon("D:\\IJ\\javaCode\\puzzleGame\\engineering-practice-\\image\\login\\注册按钮.png"));
    public LoginJFrame() {
        //初始化窗体
        initJFrame();
        //初始化涂片
        initImage();
        this.setVisible(true);

    }
    //设置窗体
    private void initJFrame() {
        //JFrame jFrame=new JFrame();
        this.setSize(603,680);
        this.setTitle("登录 v1.0");//shezhibia
        this.setAlwaysOnTop(true);//设置页面置顶
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(3);
        //取消组件默认剧中
        this.setLayout(null);
        this.addKeyListener(this);//给界面添加事件
    }
    //初始化图片
    private void initImage() {

        this.getContentPane().removeAll();//清屏




        JLabel mima=new JLabel(new ImageIcon("D:\\IJ\\javaCode\\puzzleGame\\engineering-practice-\\image\\login\\密码.png"));
        mima.setBounds(160,200,32,16);
        this.getContentPane().add(mima);


        JLabel zhangh=new JLabel(new ImageIcon("D:\\IJ\\javaCode\\puzzleGame\\engineering-practice-\\image\\login\\用户名.png"));
        zhangh.setBounds(160,240,47,17);
        this.getContentPane().add(zhangh);

        JLabel talk1=new JLabel(new ImageIcon("D:\\IJ\\javaCode\\puzzleGame\\engineering-practice-\\image\\login\\对话框.png"));
        talk1.setBounds(240,190,198,40);
        this.getContentPane().add(talk1);

        JLabel talk2=new JLabel(new ImageIcon("D:\\IJ\\javaCode\\puzzleGame\\engineering-practice-\\image\\login\\对话框.png"));
        talk2.setBounds(240,230,198,40);
        this.getContentPane().add(talk2);
        //this.getContentPane().repaint();




        jtb1.setBounds(140,340,68,27);
        jtb2.setBounds(330,340,68,27);

        jtb1.addActionListener(this);
        this.getContentPane().add(jtb1);
        jtb2.addActionListener(this);
        this.getContentPane().add(jtb2);

        JLabel background=new JLabel(new ImageIcon("image\\background.png"));
        background.setBounds(40,40,508,560);
        this.getContentPane().add(background);
        this.getContentPane().repaint();
    }
    @Override
    public void actionPerformed(ActionEvent e) {


        Object source= e.getSource();//

        if (source==jtb1) {
            jtb1.setSize(200,200);
        }else if(source==jtb2){
            Random r=new Random();

            jtb2.setLocation(r.nextInt(500),r.nextInt(500));
            //jtb2.setSize(200,200);
        }
    }

    @Override
    public void keyTyped(KeyEvent keyEvent) {

    }

    @Override
    public void keyPressed(KeyEvent keyEvent) {

    }

    @Override
    public void keyReleased(KeyEvent keyEvent) {

    }

    public static void main(String[] args) {
        new LoginJFrame();
    }
}
